﻿namespace Sidvall.WorkItemManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class WorkItemAlarm : global::Sidvall.WorkItemManager.UI.Entities.Core.BusinessBase, global::Sidvall.WorkItemManager.Data.IWorkItemAlarm
    {
        #region Business Members

        #region MaxExecutionTimeAlarmDate

        private System.Nullable<System.DateTime> _MaxExecutionTimeAlarmDate = null;
        partial void OnBeforeMaxExecutionTimeAlarmDatePropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnBeforeMaxExecutionTimeAlarmDatePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterMaxExecutionTimeAlarmDatePropertyChanged();
        public System.Nullable<System.DateTime> MaxExecutionTimeAlarmDate
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>>(Sidvall.Business.ValidationManager.GetValidDateTime(_MaxExecutionTimeAlarmDate));
                OnBeforeMaxExecutionTimeAlarmDatePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _MaxExecutionTimeAlarmDate);
                OnBeforeMaxExecutionTimeAlarmDatePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("MaxExecutionTimeAlarmDate", eventData.Value, true, true, true);
                    OnAfterMaxExecutionTimeAlarmDatePropertyChanged();
                }
            }
        }

        #endregion
        #region MaxFailedExecutionAlarmDate

        private System.Nullable<System.DateTime> _MaxFailedExecutionAlarmDate = null;
        partial void OnBeforeMaxFailedExecutionAlarmDatePropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnBeforeMaxFailedExecutionAlarmDatePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterMaxFailedExecutionAlarmDatePropertyChanged();
        public System.Nullable<System.DateTime> MaxFailedExecutionAlarmDate
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>>(Sidvall.Business.ValidationManager.GetValidDateTime(_MaxFailedExecutionAlarmDate));
                OnBeforeMaxFailedExecutionAlarmDatePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _MaxFailedExecutionAlarmDate);
                OnBeforeMaxFailedExecutionAlarmDatePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("MaxFailedExecutionAlarmDate", eventData.Value, true, true, true);
                    OnAfterMaxFailedExecutionAlarmDatePropertyChanged();
                }
            }
        }

        #endregion
        #region MaxIdleTimeAlarmDate

        private System.Nullable<System.DateTime> _MaxIdleTimeAlarmDate = null;
        partial void OnBeforeMaxIdleTimeAlarmDatePropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnBeforeMaxIdleTimeAlarmDatePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterMaxIdleTimeAlarmDatePropertyChanged();
        public System.Nullable<System.DateTime> MaxIdleTimeAlarmDate
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>>(Sidvall.Business.ValidationManager.GetValidDateTime(_MaxIdleTimeAlarmDate));
                OnBeforeMaxIdleTimeAlarmDatePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _MaxIdleTimeAlarmDate);
                OnBeforeMaxIdleTimeAlarmDatePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("MaxIdleTimeAlarmDate", eventData.Value, true, true, true);
                    OnAfterMaxIdleTimeAlarmDatePropertyChanged();
                }
            }
        }

        #endregion
        #region MonitorExecutionContextId

        private int _MonitorExecutionContextId = 0;
        partial void OnBeforeMonitorExecutionContextIdPropertyGet(Sidvall.Business.PropertyEventData<int> eventData);
        partial void OnBeforeMonitorExecutionContextIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<int> eventData);
        partial void OnAfterMonitorExecutionContextIdPropertyChanged();
        public int MonitorExecutionContextId
        {
            get
            {
                Sidvall.Business.PropertyEventData<int> eventData = new Sidvall.Business.PropertyEventData<int>(_MonitorExecutionContextId);
                OnBeforeMonitorExecutionContextIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<int> eventData = new Sidvall.Business.PropertyChangeEventData<int>(value, _MonitorExecutionContextId);
                OnBeforeMonitorExecutionContextIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("MonitorExecutionContextId", eventData.Value, true, true, true);
                    OnAfterMonitorExecutionContextIdPropertyChanged();
                }
            }
        }

        #endregion
        #region SensorAlarmDate

        private System.Nullable<System.DateTime> _SensorAlarmDate = null;
        partial void OnBeforeSensorAlarmDatePropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnBeforeSensorAlarmDatePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterSensorAlarmDatePropertyChanged();
        public System.Nullable<System.DateTime> SensorAlarmDate
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>>(Sidvall.Business.ValidationManager.GetValidDateTime(_SensorAlarmDate));
                OnBeforeSensorAlarmDatePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _SensorAlarmDate);
                OnBeforeSensorAlarmDatePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("SensorAlarmDate", eventData.Value, true, true, true);
                    OnAfterSensorAlarmDatePropertyChanged();
                }
            }
        }

        #endregion
        #region WorkItemId

        private System.Nullable<long> _WorkItemId = null;
        partial void OnBeforeWorkItemIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData);
        partial void OnBeforeWorkItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterWorkItemIdPropertyChanged();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public System.Nullable<long> WorkItemId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<long>>(_WorkItemId);
                OnBeforeWorkItemIdPropertyGet(eventData);
                return eventData.Value;
            }
            internal set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _WorkItemId);
                OnBeforeWorkItemIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WorkItemId", eventData.Value, true, true, true);
                    OnAfterWorkItemIdPropertyChanged();
                }
            }
        }

        #endregion
        #region WorkItemName

        private string _WorkItemName = string.Empty;
        partial void OnBeforeWorkItemNamePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeWorkItemNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterWorkItemNamePropertyChanged();
        public string WorkItemName
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_WorkItemName);
                OnBeforeWorkItemNamePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _WorkItemName);
                OnBeforeWorkItemNamePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WorkItemName", eventData.Value, true, true, true);
                    OnAfterWorkItemNamePropertyChanged();
                }
            }
        }

        #endregion
        #region MonitorExecutionContext

        private MonitorExecutionContext _MonitorExecutionContext;
        partial void OnBeforeMonitorExecutionContextPropertyChanged(Sidvall.Business.PropertyChangeEventData<MonitorExecutionContext> eventData);
        partial void OnAfterMonitorExecutionContextPropertyChanged();
        public MonitorExecutionContext MonitorExecutionContext
        {
            get
            {
                return _MonitorExecutionContext;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<MonitorExecutionContext> eventData = new Sidvall.Business.PropertyChangeEventData<MonitorExecutionContext>(value, _MonitorExecutionContext);
                OnBeforeMonitorExecutionContextPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("MonitorExecutionContext", eventData.Value, true, true, false);
                    OnAfterMonitorExecutionContextPropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowIsValid

        public override bool DataRowIsValid(Sidvall.Data.BusinessRuleFilter filter)
        {
            return global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.DataRowIsValid(this, filter);
        }

        #endregion
        #region DataRowStateIsDirty

        public override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.DataRowStateIsDirty(this);
            }
        }

        #endregion

        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public WorkItemAlarm Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public WorkItemAlarm Copy()
        {
            return Copy(null);
        }
        public WorkItemAlarm Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new WorkItemAlarm();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemAlarm item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemAlarm item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(WorkItemAlarm destination, global::Sidvall.WorkItemManager.Data.IWorkItemAlarm source, Sidvall.Data.CopySettings copySettings);
        private void Import(WorkItemAlarm destination, global::Sidvall.WorkItemManager.Data.IWorkItemAlarm source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(WorkItemAlarm destination, WorkItemAlarm source, Sidvall.Data.CopySettings copySettings);
        private void Import(WorkItemAlarm destination, WorkItemAlarm source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.WorkItemManager.Data.IWorkItemAlarm, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.Initialize(this, settings);
        }

        #endregion
        
        #region IWorkItemAlarm Members

        System.Nullable<System.DateTime> global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.MaxExecutionTimeAlarmDate
        {
            get
            {
                return this._MaxExecutionTimeAlarmDate;
            }
            set
            {
                this._MaxExecutionTimeAlarmDate = value;
            }
        }
        System.Nullable<System.DateTime> global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.MaxFailedExecutionAlarmDate
        {
            get
            {
                return this._MaxFailedExecutionAlarmDate;
            }
            set
            {
                this._MaxFailedExecutionAlarmDate = value;
            }
        }
        System.Nullable<System.DateTime> global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.MaxIdleTimeAlarmDate
        {
            get
            {
                return this._MaxIdleTimeAlarmDate;
            }
            set
            {
                this._MaxIdleTimeAlarmDate = value;
            }
        }
        int global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.MonitorExecutionContextId
        {
            get
            {
                return this._MonitorExecutionContextId;
            }
            set
            {
                this._MonitorExecutionContextId = value;
            }
        }
        System.Nullable<System.DateTime> global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.SensorAlarmDate
        {
            get
            {
                return this._SensorAlarmDate;
            }
            set
            {
                this._SensorAlarmDate = value;
            }
        }
        System.Nullable<long> global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.WorkItemId
        {
            get
            {
                return this._WorkItemId;
            }
            set
            {
                this._WorkItemId = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.WorkItemName
        {
            get
            {
                return this._WorkItemName;
            }
            set
            {
                this._WorkItemName = value;
            }
        }
        global::Sidvall.WorkItemManager.Data.IMonitorExecutionContext global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.MonitorExecutionContext
        {
            get
            {
                return this._MonitorExecutionContext;
            }
            set
            {
                UpdateChildProperty(this._MonitorExecutionContext, value);
                this._MonitorExecutionContext = value as MonitorExecutionContext;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public WorkItemAlarm()
        {
        }

        public WorkItemAlarm(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}